package com.travelplanning.admin.controller;

import com.travelplanning.admin.common.convention.Result;
import com.travelplanning.admin.common.convention.Results;
import com.travelplanning.admin.dto.req.ContentAddReqDTO;
import com.travelplanning.admin.dto.req.ContentQueryReqDTO;
import com.travelplanning.admin.dto.req.queryByContentIdReqDTO;
import com.travelplanning.admin.dto.req.queryByTitleReqDTO;
import com.travelplanning.admin.dto.resp.ContentQueryRespDTO;
import com.travelplanning.admin.service.ContentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "文章相关接口")
@RestController
@RequiredArgsConstructor
public class ContentController {
    private final ContentService contentService;

    /**
     * 新增文章
     * @param requestparam
     * @return
     */
    @Operation(summary = "新增文章")
    @PostMapping("/api/travel-planning/v1/content/save")
    public Result<Void> addcontent(@RequestBody ContentAddReqDTO requestparam ){
            contentService.addContent(requestparam);
            return Results.success();
    }

    /**
     *查找所有文章
     */
    @Operation(summary = "查找所有文章")
    @GetMapping("/api/travel-planning/v1/content")
    public Result<List<ContentQueryRespDTO>> queryContent(){
        return Results.success(contentService.queryContent());

    }

    /**
     *根据文章名称模糊查询查找文章
     */
    @Operation(summary = "根据文章名称模糊查询查找文章")
    @PostMapping("/api/travel-planning/v1/content/queryByContentTitle")
    public Result<List<ContentQueryRespDTO>> queryContentByTitle(@RequestBody queryByTitleReqDTO requestparam){
        return Results.success(contentService.queryContentByTitle(requestparam));
    }

    /**
     * 根据文章id查找文章
     */
    @Operation(summary = "根据文章id查询查找文章")
    @PostMapping ("/api/travel-planning/v1/content/queryByContentId")
    public Result<ContentQueryRespDTO> queryContentById(@RequestBody queryByContentIdReqDTO requestparam){
        return Results.success(contentService.queryContentById(requestparam));
    }
}
